<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>导航二级菜单</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        ul {
            list-style: none;
        }
        
        .box {
            display: flex;
            flex-direction: column;
            width: 400px;
            height: 300px;
        }
        
        .top-box {
            flex-direction: row;
            width: 400px;
            height: 40px;
            text-align: center;
            line-height: 40px;
        }
        
        .top-box ul {
            display: flex;
        }
        
        .top-box li {
            width: 100px;
            color: #fff;
            background-color: #0f0;
        }
        
        .top-box li:hover {
            cursor: pointer;
        }
        
        .top-box li.active {
            background-color: #f00;
        }
        
        .bottom-box {
            width: 400px;
            height: 260px;
            background-color: #aaa;
        }
        
        .bottom-box .bottom-box-con {
            display: none;
            width: 400px;
            height: 260px;
            text-align: center;
            line-height: 260px;
        }
        
        .bottom-box .bottom-box-con.on {
            display: block;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="top-box">
            <ul>
                <li class="active">菜单一</li>
                <li>菜单二</li>
                <li>菜单三</li>
                <li>菜单四</li>
            </ul>
        </div>
        <div class="bottom-box">
            <div class="bottom-box-con on">内容一</div>
            <div class="bottom-box-con">内容二</div>
            <div class="bottom-box-con">内容三</div>
            <div class="bottom-box-con">内容四</div>
        </div>

    </div>
    <script>
        let lis = document.querySelectorAll(".top-box li")
        let cons = document.querySelectorAll(".bottom-box-con")

        lis.forEach(function(item, index) {
            item.addEventListener("click", function() {
                lis.forEach(function(item, index) {
                    item.classList.remove("active")
                })
                lis[index].classList.add("active")
                cons.forEach(function(item, index) {
                    item.classList.remove("on")

                })
                cons[index].classList.add("on")

            })

        })
    </script>

</body>

</html>